package practise.mulitThreads.ConcurrentInPractice.ServerForResponseRequest;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * Created by richard on 6/13/14.
 */
public class RequestHandler {

    private Integer max_connection =5;

    public void receive() throws IOException {
        ExecutorService executorService = getExecutor();
        ServerSocket serverSocket = new ServerSocket(80);
        while(!Thread.currentThread().isInterrupted()){
            final Socket socket = serverSocket.accept();
            executorService.execute(new Runnable() {
                @Override
                public void run() {
                    handleRequest(socket);
                }
            });
        }
        executorService.shutdownNow();
    }

    private void handleRequest(Socket connection){

    }

    private ExecutorService getExecutor(){
        return Executors.newFixedThreadPool(max_connection);

    }
}
